#ifndef HTTPMANAGER_H
#define HTTPMANAGER_H

#include "global.h"
#include "singleton.h"


#include <QString>
#include <QUrl>
#include <QObject>
#include <QNetworkAccessManager>
#include <memory>
#include <QJsonObject>
#include <QJsonDocument>
#include <QNetworkReply>


class HttpManager : public QObject, public Singleton<HttpManager>,
                    public std::enable_shared_from_this<HttpManager>
{
    Q_OBJECT

    friend class Singleton<HttpManager>;

public:
    ~HttpManager();
    void PostHttpReq(QUrl url, QJsonObject json, ReqId req_id, Modules mod);

private:
    HttpManager();

public slots:
    // 发送信号通知指定模块http响应结束，对应的模块可以开始进行回调处理
    void slot_http_finish(ReqId id, QString res, ErrorCodes err, Modules mod);


signals:
    void signal_http_finish(ReqId id, QString res, ErrorCodes err, Modules mod);
    // 注册模块http相关请求完成发送此信号
    void signal_reg_mod_finish(ReqId id, QString res, ErrorCodes err);
    void signal_reset_mod_finish(ReqId id, QString res, ErrorCodes err);
    void signal_login_mod_finish(ReqId id, QString res, ErrorCodes err);

private:
    QNetworkAccessManager m_manager;
};
#endif // HTTPMANAGER_H
